#ifndef _glutman_h_
#define _glutman_h_
#include <GL/freeglut.h>
#include <assert.h>
#include <vector>
#include <string>
#include <hash_map>
#include "LogUtil.h"
#include "ConfigUtil.h"
#include "EventHandler.h"

class EventHandler;

//TODO: Add enum with available event handlers

struct Input
{
    bool keyStates_[255];
    float mousex_;
    float mousey_;
    Input()
       : mousex_(0.0f),
         mousey_(0.0f)
    {

    }
};

class Root 
{
public:
    Input input_;

    //Singleton
    static Root* Instance(){
        if (root_ == NULL) {
            root_ = new Root();
        }
        return root_;
    }

    ~Root();
    void Initialize(int& argc, char**& argv);
    void AddEventHandler(EventHandler* eventHandler);
    EventHandler& GetActiveEventHandler();
    void SetActiveEventHandler(const int& pos);
    void SetActiveEventHandler(EventHandler* eventHandler);
    void DeleteEventHandler(const int& pos);

private:
    static Root* root_;
    
    EventHandler* activeEventHandler_;
    std::vector<EventHandler*> eventHandlers_;

    Root();
    Root(Root const&);
    static void Reshape(int width, int height);
    static void Display();
    static void Keyboard(unsigned char key, int x, int y);
    static void Entry(int state);
    static void Mouse(int button, int state, int x, int y);
    static void Motion(int x, int y);
    static void PassiveMotion(int x, int y);
    static void Idle();
    static void Shutdown();
    static void Startup();
};

#endif
